import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-03-15
 * Time: 8:36
 */
class CQueue {
    public Stack<Integer> stack1;
    public Stack<Integer> stack2;
    public CQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

//    public int deleteHead() {
//        if(stack1.isEmpty()&&stack2.isEmpty()){
//            return -1;
//        }
//        while(!stack1.isEmpty()&&stack2.isEmpty()){
//            int size = stack1.size();
//            for(int i=0;i<size;i++){
//                int top = stack1.pop();
//                stack2.push(top);
//            }
//        }
//        return stack2.pop();
//    }
    public int deleteHead() {
        if(stack1.isEmpty()&&stack2.isEmpty()){
            return -1;
        }
        if(stack2.isEmpty()){
            while(!stack1.isEmpty()){
                int top = stack1.pop();
                stack2.push(top);
            }
        }
        return stack2.pop();
    }
}

public class Test1 {
    public static void main(String[] args) {
        CQueue cQueue = new CQueue();
        System.out.println(cQueue.deleteHead());
        cQueue.appendTail(5);
        cQueue.appendTail(2);
        System.out.println(cQueue.deleteHead());
        System.out.println(cQueue.deleteHead());
    }
}
